package com.puao.util;

import org.apache.commons.codec.binary.StringUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ReadFile {

    public static List getContent(String filePath) {
        List<String[]> res = new ArrayList<>();
        try {
            File file = new File(filePath);
            List<String> list = FileUtils.readLines(file, "UTF-8");
            for(int i = 0 ; i < list.size(); i++){
                String temp = list.get(i);
                String[] strArray = temp.split(" ");
                res.add(strArray);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return res;
    }


    public static List<String> isContain(List<String> nums,List<String[]> input){
        if(CollectionUtils.isEmpty(nums)){
            return null;
        }
        List<String> res = new ArrayList<>();
        int flag = 0;
        for(int i = 0; i< input.size() ; i++){
            int count = 0;
            String[] args = input.get(i);
            for(int j =0 ;j < nums.size(); j++){
                for(int z=0; z < 5;z++){
                    if(StringUtils.equals(nums.get(j),args[z])){
                        count ++;
                    }
                }
            }
            if(count > flag){
                res.clear();
                res.add(arrayToString(args));
                flag = count;
            }else if(count == flag){
                res.add(arrayToString(args));
            }
        }
        return res;
    }

    private static String arrayToString(String[] args){
        StringBuilder sb = new StringBuilder();
        for(int i = 0 ; i < args.length ; i ++){
            sb.append(args[i]+" ");
        }
        return sb.substring(0,sb.length()-1);
    }
    public static void main(String[] args){
        List<String[]> input = getContent("D:\\guess\\32All.txt");
        List<String> nums = Arrays.asList("05","12","17","24","26");
        List<String> res = isContain(nums,input);
        for(int i=0; i< res.size(); i++){
                System.out.println(res.get(i));
        }
    }
}
